/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controler;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

/**
 *
 * @author lsf
 */
public class DBConnection {
    public List getDataLst(String querry){
//        PrintWriter pw = response.getWriter();
  List dataList= new ArrayList(); 
  String url = "jdbc:mysql://rss1.stratoslive.wso2.com/karshamarkuptool_karsha_opensource_lk";
    String username = "root1_lQrhzZUK";
    String password = "nbuser";
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl(url);
    ds.setUsername(username);
    ds.setPassword(password);

    Connection connection = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        connection = ds.getConnection();
        stmt = connection.createStatement();
        rs = stmt.executeQuery(querry);

        while (rs.next()) {
          //  int id = rs.getInt("id");
          //  String name = rs.getString("name");
     dataList.add(rs.getString(1));
        }
 
    } catch (SQLException e) {
        e.printStackTrace();
      //  pw.println(e.getMessage());
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
        return dataList;
    }
}
